#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Solution1 {
public:
    int maxDivScore(vector<int>& nums, vector<int>& divisors) {
        int res = 0, mx = -1;
        for (int div : divisors)
        {
            int cnt = 0;
            for (int num : nums)
                if (num % div == 0)
                    ++cnt;
            if (cnt > mx || (cnt == mx && div < res))
            {
                mx = cnt;
                res = div;
            }
        }
        return res;
    }
};

class Solution2 {
public:
    int getWinner(vector<int>& arr, int k) {
        int index = 0; int mx = arr[0];
        for (int i = 1; i < arr.size(); ++i)
        {
            if (arr[i] > mx)
            {
                index = i;
                mx = arr[i];
            }
        }
        if (index <= k) return mx;
        int res = 0; int cnt = 0;
        int l = 0, r = arr.size() - 1;
        while (cnt < k)
        {
            if (arr[l] > arr[l + 1])
            {
                arr.push_back(arr[l + 1]);
                arr[l + 1] = arr[l];
                if (res == arr[l]) cnt++;
                else res = arr[l], cnt = 1;
            }
            else
            {
                arr.push_back(arr[l]);
                if (res == arr[l + 1]) cnt++;
                else res = arr[l + 1], cnt = 1;
            }
            l++; r++;
        }
        return res;
    }
};

class Solution3 {
public:
    int getWinner(vector<int>& arr, int k) {
        int mx = arr[0]; int n = arr.size();
        for (int i = 1, cnt = 0; i < n; ++i)
        {
            if (arr[i] > mx)
            {
                mx = arr[i];
                cnt = 1;
            }
            else
            {
                cnt++;
            }
            if (cnt == k)
                break;
        }
        return mx;
    }
};

int main()
{
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    int l = 0, r = 0; int cur = 0, res = 0;
    while (r < n)
    {
        if (a[r] - a[l] <= k)
        {
            res = max(res, ++cur);
        }
        else
        {
            while (a[r] - a[l] > k) l++, cur--;
            cur++;
        }
        ++r;
    }
    cout << res;
    return 0;
}